﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace CochinitaCorte
{
    public partial class SettingsForm : Form
    {
        private MainForm.FormReturn ReturnedValues;
        private Settings settings;

        public SettingsForm(MainForm.FormReturn value, object _settings)
        {
            ReturnedValues = value;
            this.settings = (Settings)_settings;
            InitializeComponent();
        }

        private void Impresora_Load(object sender, EventArgs e)
        {
            foreach (string printerName in PrinterSettings.InstalledPrinters)
            {
                this.PrintersList.Items.Add(printerName.ToString());
            }
            SetLabels(settings.PrinterName);
        }
  
        private void SetLabels(string printername)
        {
            lblStatus.Text = StatusPrinter(printername);
            lblPrinter.Text = printername;
        }

        private void txtIVA_TextChanged(object sender, EventArgs e)
        {
            txtIVA.BackColor = Color.LightGreen;
        }

        private void txtIVA_Leave(object sender, EventArgs e)
        {
            txtIVA.BackColor = Color.White;
            try
            {
                //    if (txtIVA.Text.Substring(2, 1).Equals(".") && txtIVA.Text.Substring(5, 1).Equals("%"))
                //      MP.SetIVa(txtIVA.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Formato Incorrecto - el IVA debe ser 00.00% ");
            }

        }

        private bool CheckPrinter(string printername)
        {
            try
            {
                PrintDocument print = new PrintDocument();
                print.PrinterSettings.PrinterName = printername;
                return print.PrinterSettings.IsValid;
            }
            catch
            {
                return false;
            }
        }

        private string StatusPrinter(string printername)
        {
            return ((CheckPrinter(printername)) ? "Lista" : " Apagada");
        }

        private void PrintersList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetLabels(PrintersList.SelectedItem.ToString());
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {

        }

        private void btnGuardar_Click(object sender, EventArgs e)
        {

        }

        
   
    }
}
